package com.asset.dispoal.business.approval.service.command;

import com.asset.dispoal.business.approval.domain.db.mapper.RepaymentApproverMapper;
import com.asset.dispoal.business.approval.dto.ApproverListResponse;
import com.asset.dispoal.business.approval.dto.GetApproverRequest;
import com.asset.dispoal.commom.page.PagingQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import tech.mhuang.pacebox.core.ddd.BaseCommand;
import tech.mhuang.pacebox.springboot.protocol.Result;
import tech.mhuang.pacebox.springboot.protocol.data.Page;
import tech.mhuang.pacebox.springboot.protocol.data.PageVO;

import java.util.List;

/**
 * @description:
 * @author: yf
 * @date: 2022-10-11 09:41:36
 */
@Repository
public class GetApproverListCommand implements BaseCommand<GetApproverRequest, Result<PageVO<ApproverListResponse>>> {
    @Autowired
    private RepaymentApproverMapper repaymentApproverMapper;

    @Override
    public Result<PageVO<ApproverListResponse>> execute(GetApproverRequest request) {
        int userCount = repaymentApproverMapper.getUserCount(request);
        Page page = PagingQuery.getPage(userCount, request);
        PageVO<ApproverListResponse> pageVO = new PageVO<>();
        pageVO.setTotalSize(userCount);

        if (null != page) {
            List<ApproverListResponse> responses = repaymentApproverMapper.getApproverInfo(page);
            pageVO.setResult(responses);
        }
        return Result.ok(pageVO);
    }
}
